package com.woniu.controller;

import com.woniu.entity.Department;
import com.woniu.service.DepartmentService;
import com.woniu.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    /**
     * 查询所有部门
     */
    @GetMapping("/findAll")
    public ResponseUtil findAll() {
        return departmentService.findAll();
    }

    /**
     * 根据ID查询部门
     * @param deptId 部门ID
     */
    @GetMapping("/findById/{deptId}")
    public ResponseUtil findById(@PathVariable Integer deptId) {
        return departmentService.findById(deptId);
    }

    /**
     * 添加新部门
     * @param department 包含部门名称和状态的JSON对象
     */
    @PostMapping("/add")
    public ResponseUtil add(@RequestBody Department department) {
        return departmentService.add(department);
    }

    /**
     * 更新部门信息（可用于修改名称或启用/禁用状态）
     * @param department 包含部门ID、新名称或新状态的JSON对象
     */
    @PutMapping("/update")
    public ResponseUtil update(@RequestBody Department department) {
        return departmentService.update(department);
    }

    /**
     * 删除部门
     * @param deptId 部门ID
     */
    @DeleteMapping("/delete/{deptId}")
    public ResponseUtil delete(@PathVariable Integer deptId) {
        return departmentService.delete(deptId);
    }
}